﻿using System;
using System.Collections.Generic;
using System.Text;

namespace X3dTest
{
    public class IndexedFaceSet : Rendering
    {
        private string Ccw;

        public string ccw
        {
            get { return Ccw; }
            set { Ccw = value; }
        }
        private string Convex;

        public string convex
        {
            get { return Convex; }
            set { Convex = value; }
        }
        private string Solid;

        public string solid
        {
            get { return Solid; }
            set { Solid = value; }
        }
        private string CreaseAngle;

        public string creaseAngle
        {
            get { return CreaseAngle; }
            set { CreaseAngle = value; }
        }
        private string NormalIndex;

        public string normalIndex
        {
            get { return NormalIndex; }
            set { NormalIndex = value; }
        }
        private string NormalPerVertex;

        public string normalPerVertex
        {
            get { return NormalPerVertex; }
            set { NormalPerVertex = value; }
        }
        private string TexCoordIndex;

        public string texCoordIndex
        {
            get { return TexCoordIndex; }
            set { TexCoordIndex = value; }
        }

        public IndexedFaceSet()
            : base()
        {
        }

        public IndexedFaceSet(Coordinate coordinate)
            : base()
        {
            this.Ccw = "true";
            this.ColorPerVertex = "true";
            this.Convex = "true";
            this.CreaseAngle = "0";
            this.NormalPerVertex = "true";
            this.Solid = "true";
            this.TexCoordIndex = "";
            this.Coordinate = coordinate;
        }

        public IndexedFaceSet(string coordindex, Coordinate coordinate)
            : base()
        {
            this.Ccw = "true";
            this.ColorPerVertex = "true";
            this.Convex = "true";
            this.CreaseAngle = "0";
            this.NormalPerVertex = "true";
            this.Solid = "true";
            this.TexCoordIndex = "";
            this.coordIndex = coordIndex;
            this.Coordinate = coordinate;
        }

        public override string getAttrs()
        {
            return "DEF|" + this.DEF + "|string,"
                  + "USE|" + this.USE + "|string,"
                  + "ccw|" + (this.ccw == null ? "true" : "false") + "|bool,"
                  + "colorPerVertex" + (this.colorPerVertex == null ? "true" : "false") + "|bool,"
                  + "convex" + (this.convex == null ? "true" : "false") + "|bool,"
                  + "creaseAngle" + (this.creaseAngle == null ? "0.0" : this.creaseAngle) + "|float,"
                  + "normalPerVertex" + (this.normalPerVertex == null ? "true" : "false") + "|bool,"
                  + "solid" + (this.solid == null ? "true" : "false") + "|bool,"
                  + "coordIndex" + this.coordIndex + "|int,"
                  + "Coordinate" + this.Coordinate.point + "|string";
        }

        public override void setAttrs(string attrs)
        {
            string[][] temp = X3DString.getArrayByAttrs(attrs);
            for (int i = 0; i < temp.Length; i++)
            {
                switch (temp[i][0])
                {
                    case "DEF":
                        this.DEF = temp[i][1];
                        break;
                    case "USE":
                        this.USE = temp[i][1];
                        break;
                    case "ccw":
                        this.ccw = temp[i][1];
                        break;
                    case "colorPerVertex":
                        this.colorPerVertex = temp[i][1];
                        break;
                    case "convex":
                        this.convex = temp[i][1];
                        break;
                    case "creaseAngle":
                        this.creaseAngle = temp[i][1];
                        break;
                    case "normalPerVertex":
                        this.normalPerVertex = temp[i][1];
                        break;
                    case "solid":
                        this.solid = temp[i][1];
                        break;
                    case "coordIndex":
                        this.coordIndex = temp[i][1];
                        break;
                    case "Coordinate":
                        this.coordinate = new Coordinate(temp[i][1]);
                        break;
                }
            }
        }
    }
}
